package glaf;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;

import utils.GColor;

@SuppressWarnings("serial")
public class GTable extends JTable {

	public GTable() {
		this(null);
	}

	public GTable(AbstractTableModel model) {
		super(model);
		setDefaultRenderer(Object.class, new CellRendererTable());
		setFocusable(false);
		setFont(new Font("Arial", Font.PLAIN, 14));
		JTableHeader header = getTableHeader();
		header.setDefaultRenderer(new CellRendererTableHeader());
		header.setEnabled(false);
	}

	private class CellRendererTable extends DefaultTableCellRenderer {

		public CellRendererTable() {
			super();
			setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			setHorizontalAlignment(CENTER);
			setForeground(GColor.BLUE900);
			setSelectionForeground(GColor.BLUE900);
			setRowHeight(30);
			setShowGrid(false);
			setIntercellSpacing(new Dimension(0, 0));
			setBorder(null);
		}

		public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
			return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		}

	}

	private class CellRendererTableHeader extends DefaultTableCellRenderer {

		public CellRendererTableHeader() {
			super();
			setHorizontalAlignment(CENTER);
			setFont(new Font("Arial", Font.BOLD, 14));
			setForeground(GColor.WHITE);
			setBackground(GColor.BLUE700);
			setBorder(null);
		}

		public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
			return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		}

	}

}